<?php

class Default_Plugin_Globalize extends Zend_Controller_Plugin_Abstract
{

	protected $_locale = array();
	
	public function __construct($options)
	{
		if (isset($options['locale']))
		{
			$this->_locale = (array)$options['locale'];
		}
	}
	
    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
		$module = $request->getModuleName();
		if (isset($this->_locale[$module]))
		{
			$locale = new Zend_Locale($this->_locale[$module]);
			$language = $locale->getLanguage();
			$filename = "modules/{$module}/configs/{$language}.ini";
			if (is_readable($filename))
			{
				$translate = new Zend_Translate('ini', $filename, $locale);
				Zend_Registry::set('Zend_Translate', $translate);
			}
			Zend_Registry::set('Zend_Locale', $locale);
		}
	}

}

?>